package com.nf.health.app.intervention_details.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.nf.health.app.Constants;
import com.nf.health.app.R;
import com.nf.health.app.customview.MyListView;
import com.nf.health.app.fragment.IBaseFragment;
import com.nf.health.app.intervention_details.adapter.PrescriptionAdapter;
import com.nf.health.app.intervention_details.adapter.PrescriptionContentAdapter;
import com.nf.health.app.intervention_details.bean.PrescriptionVo;
import com.nf.health.app.utils.DateUtil;

import java.util.Date;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 调理处方详情fragment
 * Created by Administrator on 2016/11/10.
 */
public class PrescriptiondetailsFragment extends IBaseFragment {

    PrescriptionVo prescriptionVo = new PrescriptionVo();
    @Bind(R.id.tv_scheme_common_head_title)
    TextView tvSchemeCommonHeadTitle;
    @Bind(R.id.tv_scheme_common_head_content)
    TextView tvSchemeCommonHeadContent;
    @Bind(R.id.mylistview)
    MyListView mylistview;
    @Bind(R.id.wenxintishi)
    TextView wenxintishi;
    @Bind(R.id.yizhouduanlian)
    TextView yizhouduanlian;
    @Bind(R.id.contentlistview)//详情 listview
    MyListView contentlistview;


    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        addViewFillInRoot(R.layout.fragment_prescriptiondetails);
        ButterKnife.bind(this, rootView);
        initView();
    }

    private void initView() {
        String id = Constants.CHANGE_ABLE.INTERVENTION_ID;
        provider.requesprescription(id, "prescription");
    }

    @Override
    public void handleActionSuccess(String actionName, Object object) {
        super.handleActionSuccess(actionName, object);
        if ("prescription".equals(actionName)) {
            prescriptionVo = (PrescriptionVo) object;
            tvSchemeCommonHeadTitle.setText("调理处方");
            tvSchemeCommonHeadContent.setText(prescriptionVo.getGuide());
            PrescriptionAdapter prescriptionAdapter = new PrescriptionAdapter(getActivity(), prescriptionVo.getList());
            mylistview.setAdapter(prescriptionAdapter);
            PrescriptionContentAdapter prescriptionContentAdapter = new PrescriptionContentAdapter(getActivity(), prescriptionVo.getList());
            contentlistview.setAdapter(prescriptionContentAdapter);
            wenxintishi.setText(prescriptionVo.getSuggest());
            yizhouduanlian.setText("一周监测安排表" + "(" + DateUtil.dateToString(new Date(Long.parseLong(prescriptionVo.getStarttime())), "yyyy-MM-dd") + "至" + DateUtil.dateToString(new Date(Long.parseLong(prescriptionVo.getEndtime())), "yyyy-MM-dd") + ")");

        }
    }


    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }
}